/**
 */
package org.mro.grib.model.files.firstEdition.impl;

import java.nio.ByteBuffer;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.mro.grib.core.GribException;
import org.mro.grib.model.files.firstEdition.FirstEditionPackage;
import org.mro.grib.model.files.firstEdition.Message;
import org.mro.grib.model.files.firstEdition.sections.BinaryDataSection;
import org.mro.grib.model.files.firstEdition.sections.BitMapSection;
import org.mro.grib.model.files.firstEdition.sections.GridDefinitionSection;
import org.mro.grib.model.files.firstEdition.sections.IndicatorSection;
import org.mro.grib.model.files.firstEdition.sections.ProductDefinitionSection;
import org.mro.grib.model.files.firstEdition.sections.SectionsFactory;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Message</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.mro.grib.model.files.firstEdition.impl.MessageImpl#getStartOffset <em>Start Offset</em>}</li>
 *   <li>{@link org.mro.grib.model.files.firstEdition.impl.MessageImpl#getEndOffset <em>End Offset</em>}</li>
 *   <li>{@link org.mro.grib.model.files.firstEdition.impl.MessageImpl#getIndicatorSection <em>Indicator Section</em>}</li>
 *   <li>{@link org.mro.grib.model.files.firstEdition.impl.MessageImpl#getProductDefinitionSection <em>Product Definition Section</em>}</li>
 *   <li>{@link org.mro.grib.model.files.firstEdition.impl.MessageImpl#getGridDefinitionSection <em>Grid Definition Section</em>}</li>
 *   <li>{@link org.mro.grib.model.files.firstEdition.impl.MessageImpl#getBitMapSection <em>Bit Map Section</em>}</li>
 *   <li>{@link org.mro.grib.model.files.firstEdition.impl.MessageImpl#getBinaryDataSection <em>Binary Data Section</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class MessageImpl extends EObjectImpl implements Message {
	/**
	 * The default value of the '{@link #getStartOffset() <em>Start Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getStartOffset()
	 * @generated
	 * @ordered
	 */
	protected static final long START_OFFSET_EDEFAULT = 0L;

	/**
	 * The cached value of the '{@link #getStartOffset() <em>Start Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getStartOffset()
	 * @generated
	 * @ordered
	 */
	protected long startOffset = START_OFFSET_EDEFAULT;

	/**
	 * The default value of the '{@link #getEndOffset() <em>End Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEndOffset()
	 * @generated
	 * @ordered
	 */
	protected static final long END_OFFSET_EDEFAULT = 0L;

	/**
	 * The cached value of the '{@link #getEndOffset() <em>End Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEndOffset()
	 * @generated
	 * @ordered
	 */
	protected long endOffset = END_OFFSET_EDEFAULT;

	/**
	 * The cached value of the '{@link #getIndicatorSection() <em>Indicator Section</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getIndicatorSection()
	 * @generated
	 * @ordered
	 */
	protected IndicatorSection indicatorSection;

	/**
	 * The cached value of the '{@link #getProductDefinitionSection() <em>Product Definition Section</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getProductDefinitionSection()
	 * @generated
	 * @ordered
	 */
	protected ProductDefinitionSection productDefinitionSection;

	/**
	 * The cached value of the '{@link #getGridDefinitionSection() <em>Grid Definition Section</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getGridDefinitionSection()
	 * @generated
	 * @ordered
	 */
	protected GridDefinitionSection gridDefinitionSection;

	/**
	 * The cached value of the '{@link #getBitMapSection() <em>Bit Map Section</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getBitMapSection()
	 * @generated
	 * @ordered
	 */
	protected BitMapSection bitMapSection;

	/**
	 * The cached value of the '{@link #getBinaryDataSection() <em>Binary Data Section</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getBinaryDataSection()
	 * @generated
	 * @ordered
	 */
	protected BinaryDataSection binaryDataSection;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected MessageImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return FirstEditionPackage.Literals.MESSAGE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public long getStartOffset() {
		return startOffset;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setStartOffset(long newStartOffset) {
		long oldStartOffset = startOffset;
		startOffset = newStartOffset;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, FirstEditionPackage.MESSAGE__START_OFFSET, oldStartOffset, startOffset));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public long getEndOffset() {
		return endOffset;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setEndOffset(long newEndOffset) {
		long oldEndOffset = endOffset;
		endOffset = newEndOffset;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, FirstEditionPackage.MESSAGE__END_OFFSET, oldEndOffset, endOffset));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public IndicatorSection getIndicatorSection() {
		return indicatorSection;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetIndicatorSection(IndicatorSection newIndicatorSection, NotificationChain msgs) {
		IndicatorSection oldIndicatorSection = indicatorSection;
		indicatorSection = newIndicatorSection;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, FirstEditionPackage.MESSAGE__INDICATOR_SECTION, oldIndicatorSection, newIndicatorSection);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setIndicatorSection(IndicatorSection newIndicatorSection) {
		if (newIndicatorSection != indicatorSection) {
			NotificationChain msgs = null;
			if (indicatorSection != null)
				msgs = ((InternalEObject)indicatorSection).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - FirstEditionPackage.MESSAGE__INDICATOR_SECTION, null, msgs);
			if (newIndicatorSection != null)
				msgs = ((InternalEObject)newIndicatorSection).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - FirstEditionPackage.MESSAGE__INDICATOR_SECTION, null, msgs);
			msgs = basicSetIndicatorSection(newIndicatorSection, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, FirstEditionPackage.MESSAGE__INDICATOR_SECTION, newIndicatorSection, newIndicatorSection));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ProductDefinitionSection getProductDefinitionSection() {
		return productDefinitionSection;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetProductDefinitionSection(ProductDefinitionSection newProductDefinitionSection, NotificationChain msgs) {
		ProductDefinitionSection oldProductDefinitionSection = productDefinitionSection;
		productDefinitionSection = newProductDefinitionSection;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, FirstEditionPackage.MESSAGE__PRODUCT_DEFINITION_SECTION, oldProductDefinitionSection, newProductDefinitionSection);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setProductDefinitionSection(ProductDefinitionSection newProductDefinitionSection) {
		if (newProductDefinitionSection != productDefinitionSection) {
			NotificationChain msgs = null;
			if (productDefinitionSection != null)
				msgs = ((InternalEObject)productDefinitionSection).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - FirstEditionPackage.MESSAGE__PRODUCT_DEFINITION_SECTION, null, msgs);
			if (newProductDefinitionSection != null)
				msgs = ((InternalEObject)newProductDefinitionSection).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - FirstEditionPackage.MESSAGE__PRODUCT_DEFINITION_SECTION, null, msgs);
			msgs = basicSetProductDefinitionSection(newProductDefinitionSection, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, FirstEditionPackage.MESSAGE__PRODUCT_DEFINITION_SECTION, newProductDefinitionSection, newProductDefinitionSection));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public GridDefinitionSection getGridDefinitionSection() {
		return gridDefinitionSection;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetGridDefinitionSection(GridDefinitionSection newGridDefinitionSection, NotificationChain msgs) {
		GridDefinitionSection oldGridDefinitionSection = gridDefinitionSection;
		gridDefinitionSection = newGridDefinitionSection;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, FirstEditionPackage.MESSAGE__GRID_DEFINITION_SECTION, oldGridDefinitionSection, newGridDefinitionSection);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setGridDefinitionSection(GridDefinitionSection newGridDefinitionSection) {
		if (newGridDefinitionSection != gridDefinitionSection) {
			NotificationChain msgs = null;
			if (gridDefinitionSection != null)
				msgs = ((InternalEObject)gridDefinitionSection).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - FirstEditionPackage.MESSAGE__GRID_DEFINITION_SECTION, null, msgs);
			if (newGridDefinitionSection != null)
				msgs = ((InternalEObject)newGridDefinitionSection).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - FirstEditionPackage.MESSAGE__GRID_DEFINITION_SECTION, null, msgs);
			msgs = basicSetGridDefinitionSection(newGridDefinitionSection, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, FirstEditionPackage.MESSAGE__GRID_DEFINITION_SECTION, newGridDefinitionSection, newGridDefinitionSection));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public BitMapSection getBitMapSection() {
		return bitMapSection;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetBitMapSection(BitMapSection newBitMapSection, NotificationChain msgs) {
		BitMapSection oldBitMapSection = bitMapSection;
		bitMapSection = newBitMapSection;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, FirstEditionPackage.MESSAGE__BIT_MAP_SECTION, oldBitMapSection, newBitMapSection);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setBitMapSection(BitMapSection newBitMapSection) {
		if (newBitMapSection != bitMapSection) {
			NotificationChain msgs = null;
			if (bitMapSection != null)
				msgs = ((InternalEObject)bitMapSection).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - FirstEditionPackage.MESSAGE__BIT_MAP_SECTION, null, msgs);
			if (newBitMapSection != null)
				msgs = ((InternalEObject)newBitMapSection).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - FirstEditionPackage.MESSAGE__BIT_MAP_SECTION, null, msgs);
			msgs = basicSetBitMapSection(newBitMapSection, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, FirstEditionPackage.MESSAGE__BIT_MAP_SECTION, newBitMapSection, newBitMapSection));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public BinaryDataSection getBinaryDataSection() {
		return binaryDataSection;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetBinaryDataSection(BinaryDataSection newBinaryDataSection, NotificationChain msgs) {
		BinaryDataSection oldBinaryDataSection = binaryDataSection;
		binaryDataSection = newBinaryDataSection;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, FirstEditionPackage.MESSAGE__BINARY_DATA_SECTION, oldBinaryDataSection, newBinaryDataSection);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setBinaryDataSection(BinaryDataSection newBinaryDataSection) {
		if (newBinaryDataSection != binaryDataSection) {
			NotificationChain msgs = null;
			if (binaryDataSection != null)
				msgs = ((InternalEObject)binaryDataSection).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - FirstEditionPackage.MESSAGE__BINARY_DATA_SECTION, null, msgs);
			if (newBinaryDataSection != null)
				msgs = ((InternalEObject)newBinaryDataSection).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - FirstEditionPackage.MESSAGE__BINARY_DATA_SECTION, null, msgs);
			msgs = basicSetBinaryDataSection(newBinaryDataSection, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, FirstEditionPackage.MESSAGE__BINARY_DATA_SECTION, newBinaryDataSection, newBinaryDataSection));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case FirstEditionPackage.MESSAGE__INDICATOR_SECTION:
				return basicSetIndicatorSection(null, msgs);
			case FirstEditionPackage.MESSAGE__PRODUCT_DEFINITION_SECTION:
				return basicSetProductDefinitionSection(null, msgs);
			case FirstEditionPackage.MESSAGE__GRID_DEFINITION_SECTION:
				return basicSetGridDefinitionSection(null, msgs);
			case FirstEditionPackage.MESSAGE__BIT_MAP_SECTION:
				return basicSetBitMapSection(null, msgs);
			case FirstEditionPackage.MESSAGE__BINARY_DATA_SECTION:
				return basicSetBinaryDataSection(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case FirstEditionPackage.MESSAGE__START_OFFSET:
				return getStartOffset();
			case FirstEditionPackage.MESSAGE__END_OFFSET:
				return getEndOffset();
			case FirstEditionPackage.MESSAGE__INDICATOR_SECTION:
				return getIndicatorSection();
			case FirstEditionPackage.MESSAGE__PRODUCT_DEFINITION_SECTION:
				return getProductDefinitionSection();
			case FirstEditionPackage.MESSAGE__GRID_DEFINITION_SECTION:
				return getGridDefinitionSection();
			case FirstEditionPackage.MESSAGE__BIT_MAP_SECTION:
				return getBitMapSection();
			case FirstEditionPackage.MESSAGE__BINARY_DATA_SECTION:
				return getBinaryDataSection();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case FirstEditionPackage.MESSAGE__START_OFFSET:
				setStartOffset((Long)newValue);
				return;
			case FirstEditionPackage.MESSAGE__END_OFFSET:
				setEndOffset((Long)newValue);
				return;
			case FirstEditionPackage.MESSAGE__INDICATOR_SECTION:
				setIndicatorSection((IndicatorSection)newValue);
				return;
			case FirstEditionPackage.MESSAGE__PRODUCT_DEFINITION_SECTION:
				setProductDefinitionSection((ProductDefinitionSection)newValue);
				return;
			case FirstEditionPackage.MESSAGE__GRID_DEFINITION_SECTION:
				setGridDefinitionSection((GridDefinitionSection)newValue);
				return;
			case FirstEditionPackage.MESSAGE__BIT_MAP_SECTION:
				setBitMapSection((BitMapSection)newValue);
				return;
			case FirstEditionPackage.MESSAGE__BINARY_DATA_SECTION:
				setBinaryDataSection((BinaryDataSection)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case FirstEditionPackage.MESSAGE__START_OFFSET:
				setStartOffset(START_OFFSET_EDEFAULT);
				return;
			case FirstEditionPackage.MESSAGE__END_OFFSET:
				setEndOffset(END_OFFSET_EDEFAULT);
				return;
			case FirstEditionPackage.MESSAGE__INDICATOR_SECTION:
				setIndicatorSection((IndicatorSection)null);
				return;
			case FirstEditionPackage.MESSAGE__PRODUCT_DEFINITION_SECTION:
				setProductDefinitionSection((ProductDefinitionSection)null);
				return;
			case FirstEditionPackage.MESSAGE__GRID_DEFINITION_SECTION:
				setGridDefinitionSection((GridDefinitionSection)null);
				return;
			case FirstEditionPackage.MESSAGE__BIT_MAP_SECTION:
				setBitMapSection((BitMapSection)null);
				return;
			case FirstEditionPackage.MESSAGE__BINARY_DATA_SECTION:
				setBinaryDataSection((BinaryDataSection)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case FirstEditionPackage.MESSAGE__START_OFFSET:
				return startOffset != START_OFFSET_EDEFAULT;
			case FirstEditionPackage.MESSAGE__END_OFFSET:
				return endOffset != END_OFFSET_EDEFAULT;
			case FirstEditionPackage.MESSAGE__INDICATOR_SECTION:
				return indicatorSection != null;
			case FirstEditionPackage.MESSAGE__PRODUCT_DEFINITION_SECTION:
				return productDefinitionSection != null;
			case FirstEditionPackage.MESSAGE__GRID_DEFINITION_SECTION:
				return gridDefinitionSection != null;
			case FirstEditionPackage.MESSAGE__BIT_MAP_SECTION:
				return bitMapSection != null;
			case FirstEditionPackage.MESSAGE__BINARY_DATA_SECTION:
				return binaryDataSection != null;
		}
		return super.eIsSet(featureID);
	}
	
	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (startOffset: "); //$NON-NLS-1$
		result.append(startOffset);
		result.append(", endOffset: "); //$NON-NLS-1$
		result.append(endOffset);
		result.append(')');
		return result.toString();
	}

	/* (non-Javadoc)
	 * @see org.mro.grib.model.files.firstEdition.Message#buildIndicatorSection(long, long, int, byte[])
	 */
	@Override
	public void buildIndicatorSection(long startOffset, long endOffset, byte edition, int messageLength)
	{
		if(indicatorSection == null)
		{
			indicatorSection = SectionsFactory.eINSTANCE.createIndicatorSection();
		}
		
		indicatorSection.setStartOffset(startOffset);
		indicatorSection.setEndOffset(endOffset);
		indicatorSection.setGribEditionNumber(edition);
		indicatorSection.setMessageLength(messageLength);
	}
	
	/* (non-Javadoc)
	 * @see org.mro.grib.model.files.firstEdition.Message#buildProductDefinitionSection(long, long, int, byte[])
	 */
	@Override
	public void buildProductDefinitionSection(long startOffset, long endOffset, int length, byte[] binarySection) {
		
		if(productDefinitionSection == null)
		{
			productDefinitionSection = SectionsFactory.eINSTANCE.createProductDefinitionSection();
		}
		
		productDefinitionSection.setStartOffset(startOffset);
		productDefinitionSection.setEndOffset(endOffset);
		productDefinitionSection.setLength(length);
		productDefinitionSection.initialise(ByteBuffer.wrap(binarySection));
	}

	/* (non-Javadoc)
	 * @see org.mro.grib.model.files.firstEdition.Message#buildGridDefinitionSection(long, long, int, byte[])
	 */
	@Override
	public void buildGridDefinitionSection(long startOffset, long endOffset, int length, byte[] binarySection) throws GribException {
		
		if(gridDefinitionSection == null)
		{
			gridDefinitionSection = SectionsFactory.eINSTANCE.createGridDefinitionSection();
		}
		
		gridDefinitionSection.setStartOffset(startOffset);
		gridDefinitionSection.setEndOffset(endOffset);
		gridDefinitionSection.setLength(length);
		gridDefinitionSection.initialise(ByteBuffer.wrap(binarySection));
	}

	/* (non-Javadoc)
	 * @see org.mro.grib.model.files.firstEdition.Message#buildBitmapSection(long, long, int, byte[])
	 */
	@Override
	public void buildBitmapSection(long startOffset, long endOffset, int length, byte[] binarySection) {
		
		if(bitMapSection == null)
		{
			bitMapSection = SectionsFactory.eINSTANCE.createBitMapSection();
		}
		
		bitMapSection.setStartOffset(startOffset);
		bitMapSection.setEndOffset(endOffset);
		bitMapSection.setLength(length);
		bitMapSection.initialise(ByteBuffer.wrap(binarySection));
	}
	

	/* (non-Javadoc)
	 * @see org.mro.grib.model.files.firstEdition.Message#buildBinaryDataSection(long, long, int, byte[])
	 */
	@Override
	public void buildBinaryDataSection(long startOffset, long endOffset, int length, byte[] binarySection) {
		
		if(binaryDataSection == null)
		{
			binaryDataSection = SectionsFactory.eINSTANCE.createBinaryDataSection();
		}
		
		binaryDataSection.setStartOffset(startOffset);
		binaryDataSection.setEndOffset(endOffset);
		binaryDataSection.setLength(length);
		binaryDataSection.initialise(ByteBuffer.wrap(binarySection));
	}
	
} //MessageImpl
